#include "stat_report.h"

Stat_Report::Stat_Report(Http_Post *parent) :
    Http_Post(parent)
{

}

Stat_Report::~Stat_Report()
{

}

void Stat_Report::firstRequestSuccess(QString uuid)
{
    QString url = WX_SERVER_HOST + WX_CGI_PATH + "webwxstatreport?type=1&r=" +
        QString::number(time(NULL));
#if QWX_DEBUG
    qDebug() << "DEBUG:" << __PRETTY_FUNCTION__ << url;
#endif
    QString json = "{\"BaseRequest\":{\"Uin\":0,\"Sid\":0},\"Count\":1,"
        "\"List\":[{\"Type\":1,\"Text\":\"" + WX_CGI_PATH
        + "login, First Request Success, uuid: " + uuid + "\"}]}";
#if QWX_DEBUG
    qDebug() << "DEBUG:" << __PRETTY_FUNCTION__ << json;
#endif
    Http_Post::post(url, json);
}

void Stat_Report::secondRequestStart(QString uuid)
{
    QString url = WX_SERVER_HOST + WX_CGI_PATH + "webwxstatreport?type=1&r=" +
        QString::number(time(NULL));
#if QWX_DEBUG
    qDebug() << "DEBUG:" << __PRETTY_FUNCTION__ << url;
#endif
    QString json = "{\"BaseRequest\":{\"Uin\":0,\"Sid\":0},\"Count\":1,"
        "\"List\":[{\"Type\":1,\"Text\":\"" + WX_CGI_PATH
        + "login, Second Request Start, uuid: " + uuid + "\"}]}";
#if QWX_DEBUG
    qDebug() << "DEBUG:" << __PRETTY_FUNCTION__ << json;
#endif
    Http_Post::post(url, json);
}

void Stat_Report::m_post(QString host, QString uuid)
{
    QString url = host + WX_CGI_PATH + "webwxstatreport?type=1&r=" +
        QString::number(time(NULL));
#if QWX_DEBUG
    qDebug() << "DEBUG:" << __PRETTY_FUNCTION__ << url;
#endif
    QString json = "{\"BaseRequest\":{\"Uin\":0,\"Sid\":0},\"Count\":1,"
        "\"List\":[{\"Type\":1,\"Text\":\"" + WX_CGI_PATH + "login, "
        "Second Request Success, uuid: " + uuid + ", time: 190765ms\"}]}";
#if QWX_DEBUG
    qDebug() << "DEBUG:" << __PRETTY_FUNCTION__ << json;
#endif
    Http_Post::post(url, json, true);
}

void Stat_Report::postV2(QString uuid)
{
    m_post(WX_V2_SERVER_HOST, uuid);
}

void Stat_Report::finished(QNetworkReply* reply)
{
    QString replyStr = QString(reply->readAll());
#if QWX_DEBUG
    qDebug() << "DEBUG:" << __PRETTY_FUNCTION__;
    qDebug() << "DEBUG:" << replyStr;
#endif
}
